/*
 * SPDX-License-Identifier: GPL-2.0
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2023. All rights reserved.
 * Description:
 * Author: -
 * Create:
 */

#include "ossl_knl.h"
#include "hiudk3.h"
#include "hiudk_internal.h"
/**
 * @brief hiudk_alloc_cmd_buf - alloc cmd buffer
 * @param hwdev: device pointer to hwdev
 * @retval non-zero: success
 * @retval null: failure
 */
struct hinic3_cmd_buf *hiudk_alloc_cmd_buf(void *hwdev)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return NULL;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_alloc_cmd_buf != NULL))) {
        return ops->hw_ops.hiudk_alloc_cmd_buf(sdk_hwdev);
    }
    pr_err("ops is NULL! \n");
    return NULL;
}

EXPORT_SYMBOL(hiudk_alloc_cmd_buf);

/**
 * @brief hiudk_alloc_db_addr - alloc doorbell & direct wqe
 * @param hwdev: device pointer to hwdev
 * @param db_base: pointer to alloc doorbell base address
 * @param dwqe_base: pointer to alloc direct base address
 * @retval zero: success
 * @retval non-zero: failure
 */
int hiudk_alloc_db_addr(void *hwdev, void __iomem **db_base, void __iomem **dwqe_base)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return -EINVAL;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_alloc_db_addr != NULL))) {
        return ops->hw_ops.hiudk_alloc_db_addr(sdk_hwdev, db_base, dwqe_base);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}

EXPORT_SYMBOL(hiudk_alloc_db_addr);

/**
 * @brief hiudk_alloc_db_phy_addr - alloc physical doorbell & direct wqe
 * @param hwdev: device pointer to hwdev
 * @param db_base: pointer to alloc doorbell base address
 * @param dwqe_base: pointer to alloc direct base address
 * @retval zero: success
 * @retval non-zero: failure
 */
int hiudk_alloc_db_phy_addr(void *hwdev, u64 *db_base, u64 *dwqe_base)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return -EINVAL;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_alloc_db_phy_addr != NULL))) {
        return ops->hw_ops.hiudk_alloc_db_phy_addr(sdk_hwdev, db_base, dwqe_base);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}

EXPORT_SYMBOL(hiudk_alloc_db_phy_addr);

/**
 * @brief hiudk_api_csr_rd64 - read 64 byte csr
 * @param hwdev: device pointer to hwdev
 * @param dest: hardware node id
 * @param addr: reg address
 * @param val: reg value
 * @retval zero: success
 * @retval non-zero: failure
 */
int hiudk_api_csr_rd64(void *hwdev, u8 dest, u32 addr, u64 *val)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return -EINVAL;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_api_csr_rd64 != NULL))) {
        return ops->hw_ops.hiudk_api_csr_rd64(sdk_hwdev, dest, addr, val);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}

EXPORT_SYMBOL(hiudk_api_csr_rd64);

/**
 * @brief hiudk_clean_root_ctxt - clean root context
 * @param hwdev: device pointer to hwdev
 * @param channel: channel id
 * @retval zero: success
 * @retval non-zero: failure
 */
int hiudk_clean_root_ctxt(void *hwdev, u16 channel)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return -EINVAL;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_clean_root_ctxt != NULL))) {
        return ops->hw_ops.hiudk_clean_root_ctxt(sdk_hwdev, channel);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}

EXPORT_SYMBOL(hiudk_clean_root_ctxt);

/**
 * @brief hiudk_cmdq_detail_resp - cmdq detail message response
 * @param hwdev: device pointer to hwdev
 * @param mod: mod type
 * @param cmd: cmd
 * @param buf_in: message buffer in
 * @param buf_out: message buffer out
 * @param out_param: inline output data
 * @param timeout: timeout
 * @param channel: channel id
 * @retval zero: success
 * @retval non-zero: failure
 */
int hiudk_cmdq_detail_resp(void *hwdev, u8 mod, u8 cmd, struct hinic3_cmd_buf *buf_in, struct hinic3_cmd_buf *buf_out,
    u64 *out_param, u32 timeout, u16 channel)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return -EINVAL;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_cmdq_detail_resp != NULL))) {
        return ops->hw_ops.hiudk_cmdq_detail_resp(sdk_hwdev, mod, cmd, buf_in, buf_out, out_param, timeout, channel);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}

EXPORT_SYMBOL(hiudk_cmdq_detail_resp);

/**
 * @brief hiudk_cmdq_detail_resp - cmdq direct message response
 * @param hwdev: device pointer to hwdev
 * @param mod: mod type
 * @param cmd: cmd
 * @param buf_in: message buffer in
 * @param out_param: message out
 * @param timeout: timeout
 * @param channel: channel id
 * @retval zero: success
 * @retval non-zero: failure
 */
int hiudk_cmdq_direct_resp(void *hwdev, u8 mod, u8 cmd, struct hinic3_cmd_buf *buf_in,
                           u64 *out_param, u32 timeout, u16 channel)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return -EINVAL;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_cmdq_direct_resp != NULL))) {
        return ops->hw_ops.hiudk_cmdq_direct_resp(sdk_hwdev, mod, cmd, buf_in, out_param, timeout, channel);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}

EXPORT_SYMBOL(hiudk_cmdq_direct_resp);

/**
 * @brief hiudk_cmdq_detail_resp - cmdq detail message response
 * @param hwdev: device pointer to hwdev
 * @param mod: mod type
 * @param cmd: cmd
 * @param cos_id: cos id
 * @param buf_in: message buffer in
 * @param buf_out: message buffer out
 * @param out_param: inline output data
 * @param timeout: timeout
 * @param channel: channel id
 * @retval zero: success
 * @retval non-zero: failure
 */
int hiudk_cos_id_detail_resp(void *hwdev, u8 mod, u8 cmd, u8 cos_id, struct hinic3_cmd_buf *buf_in,
    struct hinic3_cmd_buf *buf_out, u64 *out_param, u32 timeout, u16 channel)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return -EINVAL;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_cos_id_detail_resp != NULL))) {
        return ops->hw_ops.hiudk_cos_id_detail_resp(sdk_hwdev, mod, cmd, cos_id, buf_in, buf_out,
                                                    out_param, timeout, channel);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}

EXPORT_SYMBOL(hiudk_cos_id_detail_resp);

/**
 * @brief hiudk_event_callback - evnet callback to notify service driver
 * @param hwdev: device pointer to hwdev
 * @param event: event info to service driver
 */
void hiudk_event_callback(void *hwdev, struct hinic3_event_info *event)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_event_callback != NULL))) {
        return ops->hw_ops.hiudk_event_callback(sdk_hwdev, event);
    }
    pr_err("ops is NULL! \n");
    return;
}

EXPORT_SYMBOL(hiudk_event_callback);

/**
 * @brief hiudk_free_cmd_buf - free cmd buffer
 * @param hwdev: device pointer to hwdev
 * @param cmd_buf: cmd buffer to free
 */
void hiudk_free_cmd_buf(void *hwdev, struct hinic3_cmd_buf *cmd_buf)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_free_cmd_buf != NULL))) {
        return ops->hw_ops.hiudk_free_cmd_buf(sdk_hwdev, cmd_buf);
    }
    pr_err("ops is NULL! \n");
    return;
}

EXPORT_SYMBOL(hiudk_free_cmd_buf);

/**
 * @brief hiudk_free_db_addr - free doorbell & direct wqe
 * @param hwdev: device pointer to hwdev
 * @param db_base: pointer to free doorbell base address
 * @param dwqe_base: pointer to free direct base address
 */
void hiudk_free_db_addr(void *hwdev, const void __iomem *db_base, void __iomem *dwqe_base)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_free_db_addr != NULL))) {
        return ops->hw_ops.hiudk_free_db_addr(sdk_hwdev, db_base, dwqe_base);
    }
    pr_err("ops is NULL! \n");
    return;
}

EXPORT_SYMBOL(hiudk_free_db_addr);

/**
 * @brief hiudk_free_db_phy_addr - free doorbell & direct wqe physical address
 * @param hwdev: device pointer to hwdev
 * @param db_base: pointer to free doorbell base address
 * @param dwqe_base: pointer to free direct base address
 */
void hiudk_free_db_phy_addr(void *hwdev, u64 db_base, u64 dwqe_base)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_free_db_phy_addr != NULL))) {
        return ops->hw_ops.hiudk_free_db_phy_addr(sdk_hwdev, db_base, dwqe_base);
    }
    pr_err("ops is NULL! \n");
    return;
}

EXPORT_SYMBOL(hiudk_free_db_phy_addr);

/**
 * @brief hiudk_func_reset - reset func
 * @param hwdev: device pointer to hwdev
 * @param func_id: global function index
 * @param reset_flag: reset flag
 * @param channel: channel id
 */
int hiudk_func_reset(void *hwdev, u16 func_id, u64 reset_flag, u16 channel)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return -EINVAL;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_func_reset != NULL))) {
        return ops->hw_ops.hiudk_func_reset(sdk_hwdev, func_id, reset_flag, channel);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}

EXPORT_SYMBOL(hiudk_func_reset);

/**
 * @brief hiudk_get_board_info - get board info
 * @param hwdev: device pointer to hwdev
 * @param info: board info
 * @param channel: channel id
 * @retval zero: success
 * @retval non-zero: failure
 */
int hiudk_get_board_info(void *hwdev, struct hinic3_board_info *info, u16 channel)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return -EINVAL;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_get_board_info != NULL))) {
        return ops->hw_ops.hiudk_get_board_info(sdk_hwdev, info, channel);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}

EXPORT_SYMBOL(hiudk_get_board_info);

/**
 * @brief hiudk_get_hw_pf_infos - get pf infos
 * @param hwdev: device pointer to hwdev
 * @param infos: pf infos
 * @param channel: channel id
 */
int hiudk_get_hw_pf_infos(void *hwdev, struct hinic3_hw_pf_infos *infos, u16 channel)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return -EINVAL;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_get_hw_pf_infos != NULL))) {
        return ops->hw_ops.hiudk_get_hw_pf_infos(sdk_hwdev, infos, channel);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}

EXPORT_SYMBOL(hiudk_get_hw_pf_infos);

int hiudk_get_hw_bond_infos(void *hwdev, struct hinic3_hw_bond_infos *infos, u16 channel)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return -EINVAL;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_get_hw_bond_infos != NULL))) {
        return ops->hw_ops.hiudk_get_hw_bond_infos(sdk_hwdev, infos, channel);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}

EXPORT_SYMBOL(hiudk_get_hw_bond_infos);

/**
 * @brief hiudk_get_service_adapter - get service adapter
 * @param hwdev: device pointer to hwdev
 * @param type: service type
 * @retval non-zero: success
 * @retval null: failure
 */
void *hiudk_get_service_adapter(void *hwdev, enum hinic3_service_type type)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return NULL;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_get_service_adapter != NULL))) {
        return ops->hw_ops.hiudk_get_service_adapter(sdk_hwdev, type);
    }
    pr_err("ops is NULL! \n");
    return NULL;
}
EXPORT_SYMBOL(hiudk_get_service_adapter);

/**
 * @brief hiudk_link_event_stats - link event stats
 * @param hwdev: device pointer to hwdev
 * @param link: link status
 */
void hiudk_link_event_stats(void *hwdev, u8 link)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_link_event_stats != NULL))) {
        return ops->hw_ops.hiudk_link_event_stats(sdk_hwdev, link);
    }
    pr_err("ops is NULL! \n");
    return;
}

EXPORT_SYMBOL(hiudk_link_event_stats);

/**
 * @brief hiudk_mbox_to_pf - vf mbox message to pf
 * @param hwdev: device pointer to hwdev
 * @param mod: mod type
 * @param cmd: cmd
 * @param buf_in: message buffer in
 * @param in_size: in buffer size
 * @param buf_out: message buffer out
 * @param out_size: out buffer size
 * @param timeout: timeout
 * @param channel: channel id
 * @retval zero: success
 * @retval non-zero: failure
 */
int hiudk_mbox_to_pf(void *hwdev, u8 mod, u16 cmd, void *buf_in, u16 in_size, void *buf_out,
                     u16 *out_size, u32 timeout, u16 channel)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return -EINVAL;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_mbox_to_pf != NULL))) {
        return ops->hw_ops.hiudk_mbox_to_pf(sdk_hwdev, mod, cmd, buf_in, in_size, buf_out, out_size, timeout, channel);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}

EXPORT_SYMBOL(hiudk_mbox_to_pf);

/**
 * @brief hiudk_mbox_to_vf - mbox message to vf
 * @param hwdev: device pointer to hwdev
 * @param vf_id: vf index
 * @param mod: mod type
 * @param cmd: cmd
 * @param buf_in: message buffer in
 * @param in_size: in buffer size
 * @param buf_out: message buffer out
 * @param out_size: out buffer size
 * @param timeout: timeout
 * @param channel: channel id
 * @retval zero: success
 * @retval non-zero: failure
 */
int hiudk_mbox_to_vf(void *hwdev, u16 vf_id, u8 mod, u16 cmd, void *buf_in, u16 in_size, void *buf_out, u16 *out_size,
    u32 timeout, u16 channel)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return -EINVAL;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_mbox_to_vf != NULL))) {
        return ops->hw_ops.hiudk_mbox_to_vf(sdk_hwdev, vf_id, mod, cmd, buf_in, in_size,
                                            buf_out, out_size, timeout, channel);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}

EXPORT_SYMBOL(hiudk_mbox_to_vf);

int hiudk_mbox_to_vf_no_ack(void *hwdev, u16 vf_id, u8 mod, u16 cmd, void *buf_in, u16 in_size, void *buf_out,
    u16 *out_size, u16 channel)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;
 
    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return -EINVAL;
    }
 
    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_mbox_to_vf_no_ack != NULL))) {
        return ops->hw_ops.hiudk_mbox_to_vf_no_ack(sdk_hwdev, vf_id, mod, cmd, buf_in, in_size,
                                                   buf_out, out_size, channel);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}

EXPORT_SYMBOL(hiudk_mbox_to_vf_no_ack);

int hiudk_msg_to_mgmt_api_chain_async(void *hwdev, u8 mod, u16 cmd, const void *buf_in, u16 in_size)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return -EINVAL;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_msg_to_mgmt_api_chain_async != NULL))) {
        return ops->hw_ops.hiudk_msg_to_mgmt_api_chain_async(sdk_hwdev, mod, cmd, buf_in, in_size);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}

EXPORT_SYMBOL(hiudk_msg_to_mgmt_api_chain_async);

/**
 * @brief hiudk_msg_to_mgmt_async - msg to management cpu async
 * @param hwdev: device pointer to hwdev
 * @param mod: mod type
 * @param cmd: cmd
 * @param buf_in: message buffer in
 * @param in_size: in buffer size
 * @param channel: channel id
 * @retval zero: success
 * @retval non-zero: failure
 *
 * The function does not sleep inside, allowing use in irq context
 */
int hiudk_msg_to_mgmt_async(void *hwdev, u8 mod, u16 cmd, void *buf_in, u16 in_size, u16 channel)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return -EINVAL;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_msg_to_mgmt_async != NULL))) {
        return ops->hw_ops.hiudk_msg_to_mgmt_async(sdk_hwdev, mod, cmd, buf_in, in_size, channel);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}

EXPORT_SYMBOL(hiudk_msg_to_mgmt_async);

/**
 * @brief hiudk_msg_to_mgmt_no_ack - msg to management cpu don't need no ack
 * @param hwdev: device pointer to hwdev
 * @param mod: mod type
 * @param cmd: cmd
 * @param buf_in: message buffer in
 * @param in_size: in buffer size
 * @param channel: channel id
 * @retval zero: success
 * @retval non-zero: failure
 *
 * The function will sleep inside, and it is not allowed to be used in
 * interrupt context
 */
int hiudk_msg_to_mgmt_no_ack(void *hwdev, u8 mod, u16 cmd, void *buf_in, u16 in_size, u16 channel)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return -EINVAL;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_msg_to_mgmt_no_ack != NULL))) {
        return ops->hw_ops.hiudk_msg_to_mgmt_no_ack(sdk_hwdev, mod, cmd, buf_in, in_size, channel);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}

EXPORT_SYMBOL(hiudk_msg_to_mgmt_no_ack);

/**
 * @brief hiudk_msg_to_mgmt_sync - msg to management cpu
 * @param hwdev: device pointer to hwdev
 * @param mod: mod type
 * @param cmd: cmd
 * @param buf_in: message buffer in
 * @param in_size: in buffer size
 * @param buf_out: message buffer out
 * @param out_size: out buffer size
 * @param timeout: timeout
 * @param channel: channel id
 * @retval zero: success
 * @retval non-zero: failure
 */
int hiudk_msg_to_mgmt_sync(void *hwdev, u8 mod, u16 cmd, void *buf_in, u16 in_size,
                           void *buf_out, u16 *out_size, u32 timeout, u16 channel)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return -EINVAL;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_msg_to_mgmt_sync != NULL))) {
        return ops->hw_ops.hiudk_msg_to_mgmt_sync(sdk_hwdev, mod, cmd, buf_in, in_size, buf_out,
                                                  out_size, timeout, channel);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}

EXPORT_SYMBOL(hiudk_msg_to_mgmt_sync);

/**
 * @brief hiudk_ppf_tmr_start - start ppf timer
 * @param hwdev: device pointer to hwdev
 * @retval zero: success
 * @retval non-zero: failure
 */
int hiudk_ppf_tmr_start(void *hwdev)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return -EINVAL;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_ppf_tmr_start != NULL))) {
        return ops->hw_ops.hiudk_ppf_tmr_start(sdk_hwdev);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}

EXPORT_SYMBOL(hiudk_ppf_tmr_start);

/**
 * @brief hiudk_ppf_tmr_stop - stop ppf timer
 * @param hwdev: device pointer to hwdev
 * @retval zero: success
 * @retval non-zero: failure
 */
int hiudk_ppf_tmr_stop(void *hwdev)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return -EINVAL;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_ppf_tmr_stop != NULL))) {
        return ops->hw_ops.hiudk_ppf_tmr_stop(sdk_hwdev);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}

EXPORT_SYMBOL(hiudk_ppf_tmr_stop);

/**
 * @brief hiudk_set_root_ctxt - set root context
 * @param hwdev: device pointer to hwdev
 * @param rq_depth: rq depth
 * @param sq_depth: sq depth
 * @param rx_buf_sz: rx buffer size
 * @param channel: channel id
 * @retval zero: success
 * @retval non-zero: failure
 */
int hiudk_set_root_ctxt(void *hwdev, u32 rq_depth, u32 sq_depth, int rx_buf_sz, u16 channel)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return -EINVAL;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_set_root_ctxt != NULL))) {
        return ops->hw_ops.hiudk_set_root_ctxt(sdk_hwdev, rq_depth, sq_depth, rx_buf_sz, channel);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}

EXPORT_SYMBOL(hiudk_set_root_ctxt);

/**
 * @brief hiudk_sm_ctr_rd64 - big counter 64 read
 * @param hwdev: device pointer to hwdev
 * @param node: the node id
 * @param instance: instance id
 * @param ctr_id: counter id
 * @param value: read counter value ptr
 * @retval zero: success
 * @retval non-zero: failure
 */
int hiudk_sm_ctr_rd64(void *hwdev, u8 node, u8 instance, u32 ctr_id, u64 *value)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return -EINVAL;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_sm_ctr_rd64 != NULL))) {
        return ops->hw_ops.hiudk_sm_ctr_rd64(sdk_hwdev, node, instance, ctr_id, value);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}

EXPORT_SYMBOL(hiudk_sm_ctr_rd64);

int hiudk_mbox_ppf_to_host(void *hwdev, u8 mod, u16 cmd, u8 host_id, void *buf_in, u16 in_size, void *buf_out,
    u16 *out_size, u32 timeout, u16 channel)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return -EINVAL;
    }
    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_mbox_ppf_to_host != NULL))) {
        return ops->hw_ops.hiudk_mbox_ppf_to_host(sdk_hwdev, mod, cmd, host_id, buf_in, in_size,
                                                  buf_out, out_size, timeout, channel);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}
EXPORT_SYMBOL(hiudk_mbox_ppf_to_host);

int hiudk_get_ceq_info(void *hwdev, u16 q_id, struct hinic3_ceq_info *ceq_info)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return -EINVAL;
    }
    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_get_ceq_info != NULL))) {
        return ops->hw_ops.hiudk_get_ceq_info(sdk_hwdev, q_id, ceq_info);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}
EXPORT_SYMBOL(hiudk_get_ceq_info);

int hiudk_set_ceq_irq_disable(void *hwdev, u16 q_id)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;
    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return -EINVAL;
    }
    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_set_ceq_irq_disable != NULL))) {
        return ops->hw_ops.hiudk_set_ceq_irq_disable(sdk_hwdev, q_id);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}
EXPORT_SYMBOL(hiudk_set_ceq_irq_disable);

int hiudk_get_ceq_page_phy_addr(void *hwdev, u16 q_id, u16 page_idx, u64 *page_phy_addr)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;
    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return -EINVAL;
    }
    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_get_ceq_page_phy_addr != NULL))) {
        return ops->hw_ops.hiudk_get_ceq_page_phy_addr(sdk_hwdev, q_id, page_idx, page_phy_addr);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}
EXPORT_SYMBOL(hiudk_get_ceq_page_phy_addr);

int hiudk_init_single_ceq_status(void *hwdev, u16 q_id)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;
    if (unlikely(!CHECK_UDK_DEV(hwdev))) {
        pr_err("hwdev is error! \n");
        return -EINVAL;
    }
    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(hwdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(hwdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_init_single_ceq_status != NULL))) {
        return ops->hw_ops.hiudk_init_single_ceq_status(sdk_hwdev, q_id);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}
EXPORT_SYMBOL(hiudk_init_single_ceq_status);
